<?php

use Biz\model\store\StoreImagesModel;
use Biz\model\store\StoreVideoModel;
use Biz\service\Store\StoreHomeService;

/**
 * Description: 视频影音列表
 * Created by IntelliJ IDEA.
 * User: 玉坤
 * Date: 2021/7/28
 * Time: 14:48
 */
class AudioVisualListAction extends ActionPlugin
{
    public const USER_LEVEL = self::LEVEL_NOTHING;
    public const PAGE_SIZE = 20;

    /**
     * @throws Exception
     */
    public function main()
    {
        $type = $this->getRequest()->getPost('type', '');
        $store_id = $this->getRequest()->getPost('store_id', 0);
        $page = $this->getRequest()->getPost('page', 1);
        $per_page = $this->getRequest()->getPost('per_page', self::PAGE_SIZE);
        if (!$type || !$store_id) {
            throw new \Exception('非法传参');
        }
        $start = ($page - 1) * $per_page;
        $where_ext['LIMIT'] = [$start, $per_page];
        $data = [
            'total' => 0,
            'list' => [],
            'is_over' => 1
        ];
        if ($type === "video") {
            $where_ext['check_status'] = StoreVideoModel::PASS;
            $data['total'] = StoreVideoModel::getCount(['store_id' => $store_id, 'check_status' => StoreVideoModel::PASS]);
            $field = ['id','store_id','video_id','cover_img_id','title'];
            $data['list'] = StoreHomeService:: getVideoList($store_id, $field, $where_ext);
        } else {
            $where_ext['check_status'] = StoreImagesModel::PASS;
            $data['total'] = StoreImagesModel::getCount(['store_id' => $store_id, 'check_status' => StoreImagesModel::PASS]);
            $field = ['id', 'store_id','img_id'];
            $data['list'] = StoreHomeService:: getImageList($store_id, $field, $where_ext);
        }
        $current = $page * $per_page;
        $data['is_over'] = ($data['total'] <= $current) ? 1 : 0;
        $this->setSuccess($data);

    }
}